#!/usr/bin/python
# -*- coding: utf-8 -*-

import glob, sys, os, re, string
import pepe.p_txt.bigtxt as bt
import pepe.p_datetime.date_format as df
import pepe.glib as g

'''
Accounting Period: December, 98                         XXXXXXXXXXXXXXXXXXXXXXX                                  Page no  :        1
Acct Month/Cycle : 9812/07                               GENERAL LEDGER SYSTEM                                   Report ID: UAS4610R
Run Date         : 99/01/08                                                                                      Version  :  F.01.00
Run Time         : 19:35:19                             TRIAL BALANCE WORKSHEET                         *** COMPANY CONFIDENTIAL ***
Entity: 61  Sub-Entity: ALL
           <------------------Y E A R - T O - D A T E-----------------> <-----------------C U R R E N T   M O N T H---------------->
ACCT LL IC        U.S. DOLLARS       LOCAL CURRENCY        ADJUSTMENTS          U.S. DOLLARS       LOCAL CURRENCY       ADJUSTMENTS
------------------------------------------------------------------------------------------------------------------------------------
0944 00 00          209,087.33-                0.00        3690,669.27-          110,506.01-                0.00        2044,361.22-
0945 00 00          339,254.50-                0.00        5990,038.85-          180,271.50-                0.00        3335,022.75-
'''

o = open('v-mask.output.csv', 'w')
d = open('v-mask.dropped.#', 'w')

'''
 r"""\\...\MEGL_61_1998_December.txt""", 
 r"""\\...\MEGL_71_1998_Dec.txt"""
'''

path_file_masks = [
 r"""\\Rawdata\MEGL\2010-09-17\extracted\EN 61\TB reports FY1999-FY2004\*.txt""", 
 r"""\\Rawdata\MEGL\2010-09-17\extracted\EN 71\TB reports FY1999-FY2004\*.txt"""
]

for path_file_mask in path_file_masks:
    #for inpfile in glob.glob(DT_PATH + '\\*.txt'):
    
    print path_file_mask

    #for inpfile in glob.glob('*.txt'):    
    for inpfile in glob.glob(path_file_mask):

        fn = string.split(inpfile, '\x5C')[-1]
        print fn

        for line in bt.lines(inpfile):
    
            line = re.sub('\n', '', line)
            
            if re.search('^\d{4} [A-Z0-9][|A-Z0-9\$] [A-Z0-9]{2} .{16}\..{3} .{16}\..{3} .{14}\..{3} .{16}\..{3} .{16}\..{3} .{14}\..{2}', line):
                o.write(line + '\n')
            else:
                d.write(line + '\n')

o.close()
d.close()